<?php
 /*
 * 1626cms 說明頁管理
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once('../data/config.php');
require_once('./include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/admin_explain_fun.php');
$act = !empty($_GET['act']) ? trim($_GET['act']) : 'list';
if($act == 'list'){
require_once(ADMIN_ROOT_PATH.'include/page.class.php');
$type_id=$_GET['type_id'];
$key=trim($_POST['key']);
!empty($_POST['perpage'])?(setcookie('perpage',intval($_POST['perpage']))).($perpage=intval($_POST['perpage'])):($perpage= !empty($_COOKIE['perpage'])? $_COOKIE['perpage'] :'10');
$get_explain_sql=" where id is not null ";
!empty($type_id)?($get_explain_sql.=" and  type_id=".$type_id):'';
!empty($key)?($get_explain_sql.=" and title like '%{$key}%'"):'';
$total_sql="SELECT COUNT(*) AS num FROM ".table('explain').$get_explain_sql;
$page = new page(array('total'=>get_total($total_sql), 'perpage'=>$perpage));
$currenpage=$page->nowindex;
$offset=($currenpage-1)*$perpage;
$explain_list = get_explain($offset, $perpage,$get_explain_sql);
$smarty->assign('act',$act);//標簽ID
$smarty->assign('get_explain_category',get_explain_category());//分類列表
$smarty->assign('explain_list',$explain_list);//說明頁列表
$smarty->assign('page',$page->show(3));//分頁符
$smarty->assign('type_id',$type_id);//分類GET
$smarty->assign('key',$key);//關鍵字POST
$smarty->assign('perpage',$perpage);//每頁顯示數量POST
$smarty->assign('pageheader',"管理中心 - 說明頁管理 - 列表");//提示標題
$smarty->display('admin_explain.htm');
}
//說明頁修改
if($act == 'edit'){
$id = !empty($_GET['id']) ? trim($_GET['id']) : '';
if ($id<>"")
{
$sql = "select * from ".table('explain')." where id=".$id;
$edit_article=$db->getone($sql);
$smarty->assign('act',$act);
$smarty->assign('edit_article',$edit_article);//讀取指定ID的說明頁
$smarty->assign('get_explain_category',get_explain_category());//獲取分類
$smarty->assign('pageheader',"管理中心 - 說明頁管理 - 修改說明頁");
$smarty->display('admin_explain_edit.htm');
}
}
//保存修改--------------------------------
if($act == 'editsave')
{
$id = !empty($_POST['id']) ? trim($_POST['id']) : showmsg('參數錯誤',1);
$title = !empty($_POST['title']) ? trim($_POST['title']) : showmsg('說明頁名字不能為空',1);
$type_id = !empty($_POST['type_id']) ? trim($_POST['type_id']) : showmsg('所屬分類不能為空',1);
$content = !empty($_POST['content']) ? trim($_POST['content']) : showmsg('內容不能為空',1);
$tit_color=$_POST['tit_color'];
$tit_b=$_POST['tit_b'];
$is_display=$_POST['is_display'];
$is_url=$_POST['is_url'];
$seo_keywords=$_POST['seo_keywords'];
$seo_description=$_POST['seo_description'];
$show_order=$_POST['show_order'];
$sql="update ".table('explain')." set type_id='".$type_id."',title='".$title."',content='".$content."',tit_color='".$tit_color."',tit_b='".$tit_b."',is_display='".$is_display."',is_url='".$is_url."',seo_keywords='".$seo_keywords."',seo_description='".$seo_description."',show_order='".$show_order."' where id=".$id;
$db->query($sql);
$link[0]['text'] = "返回說明頁列表";
$link[0]['href'] = '?';
$link[1]['text'] = "查看已修改說明頁";
$link[1]['href'] = "?act=edit&id=".$id;
showmsg("修改成功！",2,$link);
}
//添加說明頁
if($act == 'add'){
$smarty->assign('act',$act);
$smarty->assign('ty_id',$_GET['ty_id']);
$smarty->assign('get_explain_category',get_explain_category());//獲取分類
$smarty->assign('pageheader',"管理中心 - 說明頁管理 - 添加說明頁");
$smarty->display('admin_explain_add.htm');
}
//說明頁分類
if($act == 'category')
{
$smarty->assign('act',$act);
$smarty->assign('get_explain_category',get_explain_category());
$smarty->assign('pageheader',"管理中心 - 說明頁管理 - 分類管理");
$smarty->display('admin_explain_category.htm');
}
//新增說明頁分類頁面
if($act == 'category_add')
{
$smarty->assign('act',"category");
$smarty->assign('pageheader',"管理中心 - 說明頁管理 - 分類管理");
$smarty->display('admin_explain_category_add.htm');
}
//保存新增說明頁
if($act == 'addsave'){
$title = !empty($_POST['title']) ? trim($_POST['title']) : showmsg('說明頁名字不能為空',1);
$type_id = !empty($_POST['type_id']) ? trim($_POST['type_id']) : showmsg('所屬分類不能為空',1);
$content = !empty($_POST['content']) ? trim($_POST['content']) : showmsg('內容不能為空',1);
$tit_color=$_POST['tit_color'];
$tit_b=$_POST['tit_b'];
$is_display=$_POST['is_display'];
$is_url=$_POST['is_url'];
$seo_keywords=$_POST['seo_keywords'];
$seo_description=$_POST['seo_description'];
$show_order=$_POST['show_order'];
$addtime=$timestamp;
$sql = "INSERT INTO ".table('explain')." (type_id,title,content,tit_color,tit_b,is_display,is_url,seo_keywords,seo_description,addtime,show_order) VALUES  ('$type_id','$title','$content','$tit_color','$tit_b','$is_display','$is_url','$seo_keywords','$seo_description','$addtime','$show_order')";
$db->query($sql);
$link[0]['text'] = "繼續添加說明頁";
$link[0]['href'] = '?act=add&ty_id='.$type_id;
$link[1]['text'] = "返回說明頁列表";
$link[1]['href'] = '?';
showmsg("添加成功！",2,$link);
}
//保存新增的分類
if($act == 'add_category_save')
{
!empty($_POST['categoryname']) ? ($categoryname=trim($_POST['categoryname'])) : showmsg("請填寫名稱",1);
$category_order=!empty($_POST['category_order']) ? trim($_POST['category_order']):'0';
$sql = "INSERT INTO ".table('explain_category')." (categoryname,category_order) VALUES  ('$categoryname','$category_order')";
$db->query($sql);
$link[0]['text'] = "返回分類管理";
$link[0]['href'] = '?act=category';
$link[1]['text'] = "繼續添加分類";
$link[1]['href'] = "?act=category_add";
showmsg("添加成功！",2,$link);
}
//保存說明頁分類(所有)
if($act == 'category_all_save')
{
$y_id=$_POST['y_id'];
$categoryname=$_POST['categoryname'];
$category_order=$_POST['category_order'];
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$sql="update ".table('explain_category')." set categoryname='".$categoryname[$i]."',category_order='".$category_order[$i]."'  where id='$y_id[$i]'";
$db->query($sql);
}
showmsg("成功修改！",2);
}
//刪除說明頁分類
if($act == 'del_category')
{
$y_id=$_GET['y_id'];
$db->query("Delete from  ".table('explain_category')." where id=".$y_id." AND admin_set<>'1'");
showmsg("刪除成功！",2);
}
//刪除鏈接或移動鏈接（批量/單個）
if($act == 'migrate_del')
{
$y_id=$_REQUEST['y_id'];
$category=$_POST['category'];
$migrate=$_POST['migrate'];
$del_Submit=$_POST['del_Submit'];
if ($y_id=="")
{
showmsg("請選擇項目！",1);
exit;
}
//批量刪除說明頁
if ($del_Submit<>"" and is_array($y_id))
{
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$db->query("Delete from  ".table('explain')." where id=".$y_id[$i]);
}
showmsg("刪除成功！",2);
}
//單個刪除說明頁
if (!is_array($y_id))
{
$db->query("Delete from  ".table('explain')." where id=".$y_id);
showmsg("刪除成功！",2);
}
//批量移動說明頁
if ($migrate<>"" && is_array($y_id))
{
empty($category) ? showmsg("請選擇目標分類！",1) : '';
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$db->query("update ".table('explain')."  set type_id='".$category."' where id=".$y_id[$i]);
}
showmsg("轉移成功！",2);
}
}
?>
